home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / proff.zoo / proff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  9.3 KB  |  332 lines

  1. char *version = "v.1.1";
  2.  
  3. #define GLOBALS 1
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "debug.h"
  8. #include "proff.h"
  9.  
  10. #define brk brrk
  11.  
  12. /*
  13.  * G L O B A L S
  14.  *
  15.  */
  16. #ifndef vms
  17. #define globaldef
  18. #endif
  19.  
  20.     /* next available char; init = 0 */
  21. globaldef int bp = -1;
  22.     /* pushed-back characters */
  23. globaldef char buf[BUFSIZE];
  24.     /* stack of file descriptors */
  25. globaldef FILE *infile[NFILES];
  26.     /* current file is infile[level] */
  27. globaldef int level;
  28.     /* stack of output file descriptors */
  29. globaldef FILE *outfile[NFILES];
  30.     /* current output is outfile[olevel]; */
  31. globaldef int olevel;
  32.     /* current output file pointer */
  33. globaldef FILE *poutput;
  34.     /* number registers a..z */
  35. globaldef int nr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  37.     /* system registers a..z */
  38. globaldef int sr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  39.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  40.     /* last char position in outbuf; init = 0 */
  41. globaldef int outp = 0;
  42.     /* width of text currently in outbuf; init = 0 */
  43. globaldef int outw = 0;
  44.     /* number of words in outbuf; init = 0 */
  45. globaldef int outwds = 0;
  46.     /* lines to be filled collect here */
  47. globaldef char outbuf[MAXOUT];
  48.                        /* word in outbuf; init=0 */
  49.     /* current output page number; init = 0 */
  50. globaldef int curpag = 0;
  51.     /* next output page number; init = 1 */
  52. globaldef int newpag = 1;
  53.     /* next line to be printed; init = 0 */
  54. globaldef int lineno = 0;
  55.     /* page length in lines; init = PAGELEN = 66 */
  56. globaldef int plval = PAGELEN;
  57.     /* page length save area */
  58. globaldef int savpl = PAGELEN;
  59.     /* margin before and including header */
  60. globaldef int m1val = 3;
  61.     /* margin after header */
  62. globaldef int m2val = 2;
  63.     /* margin after last text line */
  64. globaldef int m3val = 2;
  65.     /* bottom margin, including footer */
  66. globaldef int m4val = 3;
  67.     /* last live line on page, = plval-m3val-m4val */
  68. globaldef int bottom = PAGELEN - 5;
  69.     /* top of page title for even pages;init=NEWLINE */
  70. globaldef char ehead[MAXLINE];
  71.     /* top of page title for odd  pages;init=NEWLINE */
  72. globaldef char ohead[MAXLINE];
  73.     /* left,right margins for even header;init=inval,rmval */
  74. globaldef int ehlim[2] = { 0, PAGEWIDTH };
  75.     /* left,right margins for odd  header;init=inval,rmval */
  76. globaldef int ohlim[2] = { 0, PAGEWIDTH };
  77.     /* bot of page title for even pages;init=NEWLINE */
  78. globaldef char efoot[MAXLINE];
  79.     /* bot of page title for odd  pages;init=NEWLINE */
  80. globaldef char ofoot[MAXLINE];
  81.     /* left,right margins for even footer;init=inval,rmval */
  82. globaldef int eflim[2] = { 0, PAGEWIDTH };
  83.     /* left,right margins for odd  footer;init=inval,rmval */
  84. globaldef int oflim[2] = { 0, PAGEWIDTH };
  85.     /* flag for pausing between pages */
  86. globaldef int stopx = 0;
  87.     /* first page to begin printing with */
  88. globaldef int frstpg = 0;
  89.     /* last page to be printed */
  90. globaldef int lastpg = HUGE;
  91.     /* flag to indicate whether page should be printed */
  92. globaldef int print = YES;
  93.     /* number of blanks to offset page by; init = 0 */
  94. globaldef int  offset = 0;
  95.     /* verbose option; init = NO */
  96. globaldef int verbose = NO;
  97.     /* bolding option; init = YES; */
  98. globaldef char bolding = YES;
  99.     /* fill if YES; init = YES */
  100. globaldef int fill = YES;
  101.     /* current line spacing; init = 1 */
  102. globaldef int lsval = 1;
  103.     /* current indent; >= 0; init = 0 */
  104. globaldef int inval = 0;
  105.     /* current right margin; init = PAGEWIDTH = 60 */
  106. globaldef int rmval = PAGEWIDTH;
  107.     /* current temporary indent; init = 0 */
  108. globaldef int tival = 0;
  109.     /* number of lines to center; init = 0 */
  110. globaldef int ceval = 0;
  111.     /* flag for continuous center */
  112. globaldef char CEon = FALSE;
  113.     /* number of lines to underline; init = 0 */
  114. globaldef int ulval = 0;
  115.     /* flag for continuous underline */
  116. globaldef char ULon = FALSE;
  117.     /* number of lines to boldface; init = 0 */
  118. globaldef int boval = 0;
  119.     /* flag for continuous bolding */
  120. globaldef char BDon = FALSE;
  121.     /* justification types for heads and foots; */
  122.     /* init = LEFT, CENTER, RIGHT */
  123. globaldef int tjust[3] = { LEFT, CENTER, RIGHT };  
  124.     /* number of lines to blank suppress; init=0 */
  125. globaldef int bsval = 0;
  126.     /* right justify filled lines if YES; init=YES */
  127. globaldef int rjust = YES;
  128.     /* tab stops; init every 8 spaces */
  129. globaldef int tabs[INSIZE];
  130.     /* line control character; init = PERIOD */
  131. globaldef char cchar = '.';
  132.     /* universal escape - init = UNDERBAR */
  133. globaldef char genesc = '_';
  134.     /* character used to underline a BLANK; init = BLANK */
  135. globaldef char ulblnk = ' ';
  136.     /* scratch arrays for use by various routines */
  137. globaldef char tbuf1[MAXLINE];
  138. globaldef char tbuf2[MAXLINE];
  139. globaldef char tbuf3[MAXLINE];
  140. globaldef char ttl[MAXLINE];
  141.     /* flag to process runoff symbols only */
  142. globaldef char onlyrunoff = NO;
  143.     /* Flag to turn paging off */
  144. globaldef char paging = YES;
  145.     /* page number in roman numerals. Init = NO */
  146. globaldef char roman = NO;
  147.     /* autopar flag. Init = NO */
  148. globaldef char autopar = NO;
  149.     /* temporary indent value for autopar */
  150. globaldef int autoprv = 5;
  151.     /* hash tables for macros and variables */
  152. globaldef struct hashlist *macrotab[HASHMAX];
  153. globaldef struct hashlist *gentab[HASHMAX];
  154.     /* linked list entries for contents    */
  155. globaldef struct clist *chead = NULL;
  156. globaldef struct clist *clast = NULL;
  157.     /* keep track of what is done - VERBOSE */
  158. globaldef int p_txtlines = 0;
  159. globaldef int p_outlines = 0;
  160. globaldef int p_outpages = 0;
  161. globaldef int p_memoryus = 0;
  162.  
  163.  
  164.  
  165. /*
  166.  * M A I N L I N E   OF   P R O F F
  167.  *
  168.  */
  169.  
  170. main(argc,argv)
  171. int argc;
  172. char *argv[];
  173. {
  174.         int i,j,val,type;
  175.         char *p,c;
  176.         FILE *fp, *fopen();
  177.  
  178. #ifdef __GNUC_TOS__
  179.     extern size_t __DEFAULT_BUFSIZ__;
  180.     __DEFAULT_BUFSIZ__ = 16384;
  181. #endif
  182.         for (i = 1; i < argc; i++) {
  183.                 p = argv[i];
  184.                 if (*p == '-') {
  185.                         ++p;
  186.                         if (isalpha(*p)) {
  187.                                 c = *p++;
  188.                                 switch(c) {
  189.  
  190. /* verbose stats */        case 'v':
  191.                 case 'V':
  192.                     verbose = TRUE;
  193.                     break;
  194. /* runoff only   */        case 'r':
  195.                 case 'R':
  196.                     onlyrunoff = TRUE;
  197.                     break;
  198. /* stop for page */             case 's':
  199.                                 case 'S':
  200.                                         stopx = 1;
  201.                                         break;
  202. /* page offset   */             case 'p':
  203.                                 case 'P':
  204.                                         if (*p == 'o' || *p == 'O') {
  205.                                                 p++;
  206.                                                 j = 0;
  207.                                                 val = getval(p, &j, &type);
  208.                                                 set(&offset, val, type, 0, 0,
  209.                                                     rmval - 1);
  210.                                         }
  211.                                         else
  212.                                                 usage();
  213.                                         break;
  214. /* include file  */         case 'i':
  215.                 case 'I': /* simulate .so <filename> */
  216.                     pbstr("\n");
  217.                     pbstr(p);
  218.                     pbstr(".so ");
  219.                     break;
  220.  
  221. /* disable some  */        case 'd':
  222.                 case 'D':
  223.                     switch (*p) {
  224.  
  225.                     case 'b':
  226.                     case 'B':
  227.                         bolding = NO;
  228.                         break;
  229.                     case 'p':
  230.                     case 'P':
  231.                         paging = NO;
  232.                         break;
  233.                     default:
  234.                         break;
  235.                     }
  236.                     break;
  237.  
  238. /* garbage       */             default:
  239.                                         usage();
  240.                                 }
  241.                         }
  242.                         else
  243.                      lastpg = atoi(p);
  244.                 }
  245.                 else if (*p == '+') {
  246.                         p++;
  247.                         if ((frstpg = atoi(p)) == 0)
  248.                                 usage();
  249.                 }
  250.                 else
  251.                         break;
  252.         }
  253.         if (i == argc)
  254.                 usage();
  255.         if ((fp = fopen(argv[i], "r")) == NULL) {
  256.                 fprintf(stderr, "%s: cannot open.\n",argv[i]);
  257.                 exit(1);
  258.         }
  259.  
  260. #ifdef DEBUG
  261.     fprintf(stderr,"OPened %s for Input Fp = %ld\n",argv[i],fp);
  262. #endif
  263.         if (p = argv[++i]) {
  264.                 if ((outfile[0] = fopen(p, "w")) == NULL) {
  265.                         fprintf(stderr,"%s: cannot create.\n\n", p);
  266.                         exit(1);
  267.                 }
  268. #ifdef DEBUG
  269.     fprintf(stderr,"OPened %s for Output\n",p);
  270. #endif
  271.  
  272.     }
  273.     else
  274.     {
  275.         outfile[0] = stdout;
  276. #ifdef DEBUG
  277.     fprintf(stderr,"USing stdout for output\n");
  278. #endif
  279.     }
  280.  
  281.             /* set output file level */
  282.     olevel = 0;
  283.     poutput = outfile[0];
  284.     /*
  285.      * some minor initialisation
  286.      */
  287.  
  288.     for (i = 0; i < INSIZE; i++)
  289.         if (i % 8 == 0)
  290.             tabs[i] = YES;
  291.         else
  292.             tabs[i] = NO;
  293.  
  294.     ehead[0] = '\n';
  295.     ehead[1] = EOS;
  296.     ohead[0] = '\n';
  297.     ohead[1] = EOS;
  298.     efoot[0] = '\n';
  299.     efoot[1] = EOS;
  300.     ofoot[0] = '\n';
  301.     ofoot[1] = EOS;
  302.  
  303.             /* initialise contents linked list */
  304.  
  305.     chead = (struct clist *) malloc((size_t)sizeof(struct clist));
  306.     clast = chead;
  307.     p_memoryus += sizeof(struct clist);
  308.  
  309.         doroff(fp);
  310.         brk();
  311.         if (plval <= 100 && (lineno > 0 | outp > 0))
  312.                 space(HUGE);
  313.         putchar('\n');
  314.  
  315.     if(verbose) {
  316.         fprintf(stderr,"proff read in %6d textlines to produce\n",
  317.             p_txtlines);
  318.         fprintf(stderr,"              %6d lines\n",
  319.             p_outlines);
  320.         fprintf(stderr,"              %6d pages of formatted text.\n",
  321.             p_outpages);
  322.         fprintf(stderr,"\n%d bytes of memory was required\n",
  323.             p_memoryus);
  324.         fprintf(stderr,"for internal tables and lists.\n");
  325.     }
  326. #ifdef vms
  327.         exit(1);
  328. #else
  329.         exit(0);
  330. #endif
  331. }
  332.